home *** CD-ROM | disk | FTP | other *** search
/ Aminet 32 / Aminet 32 (1999)(Schatztruhe)[!][Aug 1999].iso / Aminet / dev / lang / Python151_Src.lha / Python1.5_Source / Amiga / utime.c < prev    next >
C/C++ Source or Header  |  1994-09-30  |  3KB  |  113 lines

  1. RCS_ID_C="$Id: utime.c,v 4.2 1994/09/29 23:09:02 jraja Exp $"
  2. /*
  3.  *      utime.c - set the modification date of the file
  4.  *
  5.  *      Copyright © 1994 AmiTCP/IP Group, 
  6.  *                       Network Solutions Development Inc.
  7.  *                       All rights reserved.
  8.  */
  9.  
  10. #include <sys/param.h>
  11. #include <sys/time.h>
  12. #include <dos/dos.h>
  13. #include <proto/dos.h>
  14. #include <utime.h>
  15. #include <errno.h>
  16.  
  17. #include <syslog.h>
  18.  
  19. #include "netlib.h"
  20.  
  21. /****** net.lib/utime *********************************************
  22.  
  23.     NAME
  24.     utime - set file access and modification times
  25.  
  26.     SYNOPSIS
  27.     #include <utime.h>
  28.  
  29.     int error = utime(const char *name, const struct utimbuf *times)
  30.  
  31.     FUNCTION
  32.     The access and modification times for the file 'name' are modified
  33.     according to the 'times'. If 'times' is NULL, the times are set to
  34.     systems current time.
  35.  
  36.     PORTABILITY
  37.     UNIX
  38.  
  39.     INPUTS
  40.     'name'  - the name of the file to be affected.
  41.  
  42.     'times' - pointer to a structure containing the time values,
  43.           defined in <utime.h> as:
  44.  
  45.               struct utimbuf {
  46.               time_t actime;    \* Access time *\
  47.               time_t modtime;    \* Modification time *\
  48.               };
  49.  
  50.           Both times are in units of seconds since Jan. 1, 1970,
  51.           Greenwich Mean Time.
  52.  
  53.           If the 'times' is given as the NULL pointer, the current
  54.           time is used.
  55.  
  56.     RESULT
  57.     Returns 0 when successful and -1 with specific error code in errno in
  58.     case of an error.
  59.  
  60.     NOTES
  61.     Since AmigaDOS files have only one time stamp, both access and
  62.     modification times cannot be supported. Since the AmigaDOS file date
  63.     is the modification time, only the 'modtime' field of the 'times' is
  64.     used.
  65.  
  66.     The conversion from 1.1.1970 based GMT to 1.1.1978 based local time is
  67.     done with external long __local_to_GMT, which is defined and
  68.     initialized by the timerinit.c module included in the net.lib.
  69.  
  70.     SEE ALSO
  71.     dos.library/DateStamp(), dos.library/SetFileDate(), net.lib/timerinit
  72.  
  73. *****************************************************************************
  74. *
  75. */
  76.  
  77. extern long __local_to_GMT; /* defined and initialized in timerinit.c */
  78.  
  79. int
  80. utime(const char *name, const struct utimbuf *times)
  81. {
  82.   struct DateStamp stamp;
  83.   unsigned long days, secs;
  84.   time_t time;
  85.  
  86.   if (times == NULL)
  87.     DateStamp(&stamp);
  88.   else {
  89.     /*
  90.      * AmigaDOS file date is the modification time
  91.      */
  92.     time = times->modtime;
  93.  
  94.     /*
  95.      * Convert time (secs since 1.1.1970 GMT) to
  96.      * AmigaDOS DateStamp (based on 1.1.1978 local time).
  97.      */
  98.     time -= __local_to_GMT; /* GMT to local */
  99.     days = (unsigned long)time / (unsigned long)(24*60*60);
  100.     secs = (unsigned long)time % (unsigned long)(24*60*60);
  101.     stamp.ds_Days = (LONG)days;
  102.     stamp.ds_Minute = (LONG)(secs / 60);
  103.     stamp.ds_Tick = (LONG)((secs % 60) * TICKS_PER_SECOND);
  104.   }
  105.  
  106.   if (!SetFileDate((STRPTR)name, &stamp)) {
  107.     set_errno(IoErr());
  108.     return -1;
  109.   }
  110.  
  111.   return 0;
  112. }
  113.